#include "MainFrame/SettingDock/LayersDock.h"
#include "MainFrame/SettingDock/LayersDock/LayerDockWidget.h"

LayersDock::LayersDock(const QString &title, QWidget *parent, Qt::WindowFlags flags):
    QDockWidget(title, parent, flags),
    m_pLayerDockWidgetsMap(nullptr)
{
    m_pLayerDockWidgetsMap = new QMap<int, LayerDockWidget*>;

    initSettingWidget();
    connetSignalToSlots();
}

LayersDock::~LayersDock()
{

}

void LayersDock::addLayerDockWidget(int nID, const QString& strBLayerName)
{
    LayerDockWidget* widget = new LayerDockWidget(this);
    widget->initBottomLayer(strBLayerName);
    this->setWidget(widget);
    m_pLayerDockWidgetsMap->insert(nID, widget);
}

void LayersDock::delLayerDockWidget(int nID)
{
    QMap<int, LayerDockWidget*>::iterator Iter = m_pLayerDockWidgetsMap->find(nID);
    if(Iter != m_pLayerDockWidgetsMap->end())
    {
        LayerDockWidget* widget = Iter.value();
        delete widget;
        m_pLayerDockWidgetsMap->remove(nID);
    }
}

void LayersDock::changeLayerDockWidget(int nID)
{
    QMap<int, LayerDockWidget*>::iterator Iter = m_pLayerDockWidgetsMap->find(nID);
    if(Iter != m_pLayerDockWidgetsMap->end())
    {
        LayerDockWidget* widget = Iter.value();
        this->setWidget(widget);
    }
}

void LayersDock::initSettingWidget()
{
    setFeatures(DockWidgetFloatable | DockWidgetMovable);
    this->setMinimumWidth(300);
    this->setMaximumWidth(500);
}

void LayersDock::connetSignalToSlots()
{

}
